package oxing.core;

import java.util.concurrent.atomic.AtomicLong;

public class System {
	private final static long multiplier = 0x5DEECE66DL;
	private final static long addend = 0xBL;
	private final static long mask = (1L << 48) - 1;
	private static AtomicLong seed = new AtomicLong((java.lang.System.nanoTime() ^ multiplier) & mask);

	private System() {
		throw new RuntimeException();
	}

	static Screen screen;

	public final static void setScreenOrientation(int orientation) {
		screen.setOrientation(orientation);
	}

	public static int next(int bits) {
		long oldseed, nextseed;
		AtomicLong seed = System.seed;
		do {
			oldseed = seed.get();
			nextseed = (oldseed * multiplier + addend) & mask;
		} while (!seed.compareAndSet(oldseed, nextseed));
		return (int) (nextseed >>> (48 - bits));
	}
}